package com.example.coursehub.coursemanagement.repository;

import com.example.coursehub.coursemanagement.entity.Chapter;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 章节数据访问接口
 */
@Repository
public interface ChapterRepository extends JpaRepository<Chapter, Long> {
    
    /**
     * 根据课程ID查找章节，按顺序排列
     */
    List<Chapter> findByCourseIdOrderByOrderNum(Long courseId);
    
    /**
     * 根据课程ID删除所有章节
     */
    void deleteByCourseId(Long courseId);
    
    /**
     * 统计课程的章节数量
     */
    long countByCourseId(Long courseId);
}